import requests


class YiShapeClient:

    def __init__(self, url="http://demo.yishape.com/"):
        self.url = url

    def text_embedding(self, sentence):
        if not self.url.endswith("/"):
            self.url = self.url + "/"
        api = self.url + "vec"
        params = {
            "query": sentence
        }
        # print(api, params)
        response = requests.post(api, data=params)
        # print(response)
        data = response.json()["vector"]
        return data


if __name__ == "__main__":
    str = "需要讨论参数传递，包括默认参数的使用，这样用户知道如何处理可选参数。例如，在Person类中设置默认年龄为0。"
    url = "http://demo.yishape.com"
    client = YiShapeClient(url)
    vec = client.text_embedding(str)
    print(vec)
